﻿

namespace Cuce.ReportingServices.MSBuild.UnitTests
{
    using System;
    using NUnit.Framework;
    using ReportingServices.UnitTests.Mock;

    /// <summary>
    /// 
    /// </summary>
    [TestFixture]
    public class UpdateReportTest
    {
        private UpdateReport i;

        private const string validFolder = "/testFolder/";
        private const string validXMLFile = @"C:\Samples\Swot\ReportingServices\Cuce.ReportingServices.MSBuild\Sample\SampleProject.xml";
        private const string validName = "testName";
        private const string validURL = "testUrl";

        /// <summary>
        /// Somes the test.
        /// </summary>
        [Test]
        public void WorkingTest()
        {
            i = new UpdateReport(new ReportingServicesMock())
                   {
                       Url = validURL,
                       Name = validName,
                       Folder = validFolder,
                       File = validXMLFile
                   };

            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update no RS.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNoRS()
        {
            i = new UpdateReport(null)
                    {
                        Name = validName,
                        Folder = validFolder,
                        File = validXMLFile
                    };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update no URL.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNoUrl()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Name = validName,
                        Folder = validFolder,
                        File = validXMLFile
                    };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the name of the services update no.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNoName()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Folder = validFolder,
                        File = validXMLFile

                    };



            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update no folder.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNoFolder()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = validName,
                        File = validXMLFile

                    };



            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update no file.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNoFile()
        {
            i = new UpdateReport(new ReportingServicesMock()) { Url = validURL, Name = validName, Folder = validFolder };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update with creditials.
        /// </summary>
        [Test]
        public void ReportingServicesUpdateWithCreditials()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = validName,
                        Folder = validFolder,
                        File = validXMLFile,
                        CredentialsDomain = "test",
                        CredentialsUserName = "test",
                        CredentialsPassword = "test"
                    };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update with proxy.
        /// </summary>
        [Test]
        public void ReportingServicesUpdateWithProxy()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = validName,
                        Folder = validFolder,
                        File =validXMLFile,
                        Proxy = true
                    };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update not A real file.
        /// </summary>
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void ReportingServicesUpdateNotARealFile()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = validName,
                        Folder = validFolder,
                        File = @"C:\ReportingServices\Cuce.ReportingServices.MSBuild\Sample\SampleProject.xml"
                    };


            Assert.IsTrue(i.Execute());
        }

        /// <summary>
        /// Reportings the services update with error.
        /// </summary>
        [Test]
        public void ReportingServicesUpdateWithError()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = "Error",
                        Folder = validFolder,
                        File =validXMLFile
                    };


            Assert.IsFalse(i.Execute());
        }

        /// <summary>
        /// Reportings the services update with warning.
        /// </summary>
        [Test]
        public void ReportingServicesUpdateWithWarning()
        {
            i = new UpdateReport(new ReportingServicesMock())
                    {
                        Url = validURL,
                        Name = "warning",
                        Folder = validFolder,
                        File = validXMLFile
                    };


            Assert.IsFalse(i.Execute());
        }
    }
}
